package model;

/**
 * 
 * This is the superclass which is extended by Basic and Recipe classes. 
 * @author Roman Pusec, Dennis Goldfinger, Marko Bilic
 *
 */
public class Food {
	protected String name;
	
	/**
	 * Constructor which sets the name. 
	 * @param name The name. 
	 */
	public Food(String name)
	{
		this.name = name;
	}
	
	/**
	 * Returns the name. 
	 * @return The name.
	 */
	public String getName()
	{
		return this.name;
	}
	
	/**
	 * Overridden toString() method which returns the name. 
	 */
	public String toString()
	{
		return this.name;
	}
	
	/**
	 * Overridden equals() method which additionally tests if the "name" 
	 * attribute of the Food/Recipe is the same. 
	 */
	@Override public boolean equals(Object o)
	{
		if(this == o)
		{
			return true;
		}
		
		if(o instanceof Basic)
		{
			Basic b = (Basic)o;
			
			if(b.getName().equals(this.name))
			{
				return true;
			}
		} 
		else if(o instanceof Recipe)
		{
			Recipe r = (Recipe)o;
			
			if(r.getName().equals(this.name))
			{
				return true;
			}
		}
		
		return false;
	}
}
